package com.fengxing.ams.web.facade.mouble.vip;

import java.util.Date;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

public interface IVipDAO extends PagingAndSortingRepository<VipVO, String>, JpaSpecificationExecutor<VipVO>  {

	VipVO findByPhone(String phone);

	VipVO findByCarNumber(String id);

	@Modifying 
	@Query("update VipVO t set t.time = t.time - :time where t.id=:id")
	void purchase(@Param("id") String id, @Param("time")Integer time);

	@Modifying 
	@Query("update VipVO t set t.vipType=0, t.time = t.time + :time, t.totalTime = t.totalTime + :time, t.totalAmount = t.totalAmount + :amount where t.id=:id")
	void updateTimeAndAmount(@Param("id")String id, @Param("time")Integer time, @Param("amount")Integer amount);
	
	@Modifying
	@Query("update VipVO t set t.phone = :phone, t.name = :name, t.carNumber = :carNumber, t.carType = :carType where t.id=:id")
	void updateVipInfo(@Param("id")String id, @Param("name")String name, @Param("phone")String phone, @Param("carNumber")String carNumber, @Param("carType")String carType);

	@Modifying
	@Query("update VipVO t set t.yearExpiredDate = :yearExpiredDate, t.totalTime=0, t.time=0,t.vipType=1, t.totalAmount=t.totalAmount+:amount where t.id=:id")
	void updateVipInfo(@Param("id")String id, @Param("yearExpiredDate")Date yearExpiredDate, @Param("amount")Integer amount);

}
